package com.spheres.quiniela.web

import com.spheres.quiniela.domain.Match
import com.spheres.quiniela.domain.FixtureNumber
import org.springframework.security.access.annotation.Secured

class AdminController {

  def matchAdmin = {
    if (params.fixtureNumber) {
      def fixtureNumber = FixtureNumber.get(params.long("fixtureNumber"))
      def matches = Match.findAllByFixtureNumber(fixtureNumber)
      [matches: matches, currentFixtureNumber: fixtureNumber]
    }
  }

  def createMatch = {
    def match = new Match()
    match.properties = params
    if (match.save(flush: true)) {
      flash.message = "Se inserto correctamente"
    }
    else {
      flash.message = "Errores: " + match.errors
    }
    redirect(action: "matchAdmin", params: [fixtureNumber: match.fixtureNumber.id])
  }

  def index = { }
}
